package com.niit.yhserver.service.impl;

import com.niit.yhpojo.dto.AdminDTO;
import com.niit.yhpojo.entity.Admin;
import com.niit.yhpojo.entity.Employee;
import com.niit.yhserver.mapper.AdminMapper;
import com.niit.yhserver.service.AdminService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {


    @Autowired
    private AdminMapper adminMapper;

    //管理员登录
    @Override
    public boolean login(@Param("username") String username, @Param("password") String password) {
        Admin login = adminMapper.login(username, password);
        if(login != null){
            return true;
        }else {
            return false;
        }

    }

    //显示全部
    @Override
    public List<Admin> getAllAdmin() {
        return adminMapper.getAllAdmin();
    }

    //按照id找管理员
    @Override
    public Admin findAdminOneById(Integer id) {
        return adminMapper.findAdminOneById(id);
    }

    //增加
    @Override
    public void addAdmin(AdminDTO adminDTO) {
        Admin admin = new Admin();

        BeanUtils.copyProperties(adminDTO,admin);

        admin.setCreateTime(LocalDateTime.now());
        admin.setUpdateTime(LocalDateTime.now());

        adminMapper.addAdmin(admin);
    }

    //更新
    @Override
    public void updateAdmin(AdminDTO adminDTO) {
        Admin admin = new Admin();
        BeanUtils.copyProperties(adminDTO,admin);

        admin.setUpdateTime(LocalDateTime.now());
        adminMapper.updateAdmin(admin);
    }

    //删
    @Override
    public void deleteAdminById(Integer id) {
        adminMapper.deleteAdminById(id);
    }
}
